<template>
	<el-main class="bg edit_wrap">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
		<el-row class="row_ce">
							<el-col v-if="$check_field('get','case_name') || $check_field('add','case_name') || $check_field('set','case_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="案例名称" prop="case_name">
												<el-input id="case_name" v-model="form['case_name']" placeholder="请输入案例名称"
							  v-if="(form['fraud_case_id'] && $check_field('set','case_name')) || (!form['fraud_case_id'] && $check_field('add','case_name'))" :disabled="disabledObj['case_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','case_name')">{{form['case_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','case_type') || $check_field('add','case_type') || $check_field('set','case_type')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="案例类型" prop="case_type">
												<el-input id="case_type" v-model="form['case_type']" placeholder="请输入案例类型"
							  v-if="(form['fraud_case_id'] && $check_field('set','case_type')) || (!form['fraud_case_id'] && $check_field('add','case_type'))" :disabled="disabledObj['case_type_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','case_type')">{{form['case_type']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','case_video') || $check_field('add','case_video') || $check_field('set','case_video')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="案例视频" prop="case_video">
												<el-upload v-if="(form['fraud_case_id'] && $check_field('set','case_video')) || (!form['fraud_case_id'] && $check_field('add','case_video'))" class="upload-demo" drag
						action="" style="max-width: 300px;width: 100%;" :http-request="upload_case_video" :limit="1" accept="video/ogg,video/mp4,video/webm">
						<i class="el-icon-upload"></i>
						<div class="el-upload__text">将视频拖到此处，或<em>点击上传</em></div>
					</el-upload>
					<div v-else-if="$check_field('get','case_video')">
						<el-button type="primary" @click="download(form['case_video'])">下载<i
								class="el-icon-download el-icon--right"></i></el-button>
					</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','case_population') || $check_field('add','case_population') || $check_field('set','case_population')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="案例人群" prop="case_population">
												<el-input id="case_population" v-model="form['case_population']" placeholder="请输入案例人群"
							  v-if="(form['fraud_case_id'] && $check_field('set','case_population')) || (!form['fraud_case_id'] && $check_field('add','case_population'))" :disabled="disabledObj['case_population_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','case_population')">{{form['case_population']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','case_description') || $check_field('add','case_description') || $check_field('set','case_description')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="案例描述" prop="case_description">
								<el-input type="textarea" id="case_description" v-model="form['case_description']" placeholder="请输入案例描述"
						v-if="(form['fraud_case_id'] && $check_field('set','case_description')) || (!form['fraud_case_id'] && $check_field('add','case_description'))" :disabled="disabledObj['case_description_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','case_description')">{{form['case_description']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','cover_photo') || $check_field('add','cover_photo') || $check_field('set','cover_photo')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="封面图片" prop="cover_photo">
								<el-upload :disabled="disabledObj['cover_photo_isDisabled']" class="avatar-uploader" drag
						accept="image/gif, image/jpeg, image/png, image/jpg" action="" :http-request="upload_cover_photo"
						:show-file-list="false" v-if="(form['fraud_case_id'] && $check_field('set','cover_photo')) || (!form['fraud_case_id'] && $check_field('add','cover_photo'))">
						<img id="cover_photo" v-if="form['cover_photo']" :src="$fullUrl(form['cover_photo'])" class="avatar">
						<i v-else class="el-icon-plus avatar-uploader-icon"></i>
					</el-upload>
					<el-image v-else-if="$check_field('get','cover_photo')" style="width: 100px; height: 100px"
						:src="$fullUrl(form['cover_photo'])" :preview-src-list="[$fullUrl(form['cover_photo'])]">
						<div slot="error" class="image-slot">
							<img src="../../../public/img/error.png" style="width: 90px; height: 90px" />
						</div>
					</el-image>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','case_content') || $check_field('add','case_content') || $check_field('set','case_content')" :xs="24" :sm="24" :lg="24" class="el_form_editor_warp">
				<el-form-item label="案例内容" prop="case_content">
					<quill-editor v-model.number="form['case_content']"
						v-if="(form['fraud_case_id'] && $check_field('set','case_content')) || (!form['fraud_case_id'] && $check_field('add','case_content')) ">
					</quill-editor>
					<div v-else-if="$check_field('get','case_content')" v-html="form['case_content']"></div>
				</el-form-item>
			</el-col>
						
	
	
		
		
	
	
	
	
	</el-row>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item v-if="$check_action('/fraud_case/view','set') || $check_action('/fraud_case/view','add') || $check_option('/fraud_case/table','examine')">
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
				<el-form-item v-else>
					<el-button @click="cancel()">返回</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				field: "fraud_case_id",
				url_add: "~/api/fraud_case/add?",
				url_set: "~/api/fraud_case/set?",
				url_get_obj: "~/api/fraud_case/get_obj?",
				url_upload: "~/api/fraud_case/upload?",

				query: {
					"fraud_case_id": 0,
				},

				form: {
								"case_name":  '', // 案例名称
										"case_type":  '', // 案例类型
										"case_video":  '', // 案例视频
										"case_population":  '', // 案例人群
										"case_description":  '', // 案例描述
										"cover_photo":  '', // 封面图片
										"case_content":  '', // 案例内容
											"fraud_case_id": 0, // ID
													},
				disabledObj:{
								"case_name_isDisabled": false,
										"case_type_isDisabled": false,
										"case_video_isDisabled": false,
										"case_population_isDisabled": false,
										"case_description_isDisabled": false,
										"cover_photo_isDisabled": false,
										"case_content_isDisabled": false,
										},

	
				
				
				
				
				
				
			
			}
		},
		methods: {

	
	
			
	
						/**
			 * 上传案例视频
			 * @param {Object} param 视频参数
			 */
			upload_case_video(param){
									this.uploadFile(param.file, "case_video");
								},
	
	
			
	
			
	
						/**
			 * 上传封面图片
			 * @param {Object} param 图片参数
			 */
			upload_cover_photo(param){
									this.uploadFile(param.file, "cover_photo");
								},
	
	
			
	
		
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
																if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
								this.form[key] = form[dbKey]
							}
							if(dbKey === "source_table"){
								this.form['source_table'] = form[dbKey];
							}
							if(dbKey === "source_id"){
								this.form['source_id'] = form[dbKey];
							}
							if(dbKey === "source_user_id"){
								this.form['source_user_id'] = form[dbKey];
							}
						})
					})
				}
																		$.db.del("form");
				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){

																																			

			},

																																																							async submit(param, func){
				if (!param) {
					param = this.form;
				}
								var pm = this.events("submit_before", Object.assign({}, param)) || param;
				var msg = await this.events("submit_check", pm);
				var ret;
				if (msg) {
					this.$toast(msg, 'danger');
				} else {
																																																									ret = this.events("submit_main", pm, func);
				}
				return ret;
			},
			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
						submit_check(param) {
																																																																																							return null;
			},

			is_view(){
				// var bl = this.user_group == "管理员";
				var bl = false;

				if(!bl){
					bl = this.$check_action('/fraud_case/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/fraud_case/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/fraud_case/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/fraud_case/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/fraud_case/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
																},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
	
	.img_multiple{
		overflow: hidden;
	}
	.img_multiple .img_block{
		float: left;
		margin-right: 5px;
		margin-bottom: 5px;
		position: relative;
	}
	.img_multiple .img_block img{
		height: 100px;
		width: auto;
	}
	.img_multiple .img_del{
		position: absolute;
		top: 5px;
		right: 5px;
		width: 20px;
		height: 20px;
		background: #0000008a;
		color: #fff;
		line-height: 20px;
		text-align: center;
		border-radius: 100%;
		cursor: pointer;
	}




</style>
